package com.itheima.tools;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

/**
 * redis工具类
 */
public class JedisUtil {
    private static JedisPool jedisPool;
    private static  String host = "192.168.72.142";
    private static  int port = 6379;
    static {
        //创建连接池的配置对象
        JedisPoolConfig config = new JedisPoolConfig();
        config.setMaxIdle(5);//闲时最大的数量
        config.setMaxTotal(100); //最大有100个
        config.setMinIdle(3);//最小闲时的数量
        jedisPool = new JedisPool(config,host,port);
    }

    /**
     * 获取redis的连接对象(用完要记得归还)
     */
    public static Jedis getJedis(){
        Jedis jedis = jedisPool.getResource();
        return jedis;

    }
}
